home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
powervww
/
pvtable.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1998-01-05
|
25KB
|
1,087 lines
// ____________________________________________________
// | |
// | Project: POWER VIEW INTERFACE |
// | File: PVTABLE.CPP |
// | Compiler: WPP386 (10.6) |
// | |
// | Subject: Tables support implementation |
// | |
// | Author: Emil Dotchevski |
// |____________________________________________________|
//
// E-mail: zajo@geocities.com
// URL: http://www.geocities.com/SiliconValley/Bay/3577
#define uses_stdio
#define uses_string
#define uses_icons
#define uses_check
#define uses_dc
#define uses_desk
#define uses_dialog
#define uses_label
#define uses_list
#define uses_system
#define uses_stddlg
#define uses_table
#define uses_win
#define DECLARE_PVTABLE_H
#include "PVuses.h"
#undef DECLARE_PVTABLE_H
#define cmTABLE_UPDATE cmUSER99
static Ttable_data *data_ptr;
static boolean dialog_table_fl = 0;
//Ttable_iterator publics:
Ttable_iterator::Ttable_iterator( int _xl, int _yl ):
Titem( _xl, _yl ),
h_beg_print( _h_beg_print ),
h_size( _h_size ),
h_count( _h_count ),
h_current( _h_current ),
v_beg_print( _v_beg_print ),
v_count( _v_count ),
v_current( _v_current )
{
grow_mode = gmGROW_BOTH;
h_beg_print=h_count=h_size=h_current=v_beg_print=v_count=v_current=hsel_org=vsel_org=0;
#ifndef NOMOUSE
set_events_mask( evMOUSE_REP, 1 );
#endif
set_flags( tfDOUBLE_CLICK_OK|tfWHOLE_LINES, 1 );
}
Ttable_iterator::Ttable_iterator( int _xl, int _yl,
uint &hsize,
uint &hbeg_print, uint &hcount, uint &hcurrent,
uint &vbeg_print, uint &vcount, uint &vcurrent ):
Titem( _xl, _yl ),
h_beg_print( hbeg_print ),
h_size( hsize ),
h_count( hcount ),
h_current( hcurrent ),
v_beg_print( vbeg_print ),
v_count( vcount ),
v_current( vcurrent )
{
grow_mode = gmGROW_BOTH;
h_beg_print=h_count=h_size=h_current=v_beg_print=v_count=v_current=hsel_org=vsel_org=0;
#ifndef NOMOUSE
set_events_mask( evMOUSE_REP, 1 );
#endif
set_flags( tfDOUBLE_CLICK_OK|tfWHOLE_LINES, 1 );
}
void Ttable_iterator::redraw( void )
{
Titem::redraw();
if( owner != NULL ) owner->redraw();
}
void Ttable_iterator::set_title( char *title )
{
if( ( owner == NULL ) || ( owner->owner == NULL ) ) return;
((Twindow *) owner->owner)->set_title( title );
#ifdef TABLEINFO
if( !owner->flags(tfDIALOG) && current_table==owner )
((Twindow *) table_info->owner)->set_title( title );
#endif
}
void Ttable_iterator::left( void )
{
if( !h_current ) return;
h_current--;
uint n=0,w=0;
for( Ttable_data *d=data;
d!=NULL && n<h_current && w<h_beg_print;
n++,w+=d->width+1,d=d->nextc );
if( w<h_beg_print ) h_beg_print -= h_beg_print-w;
}
void Ttable_iterator::right( void )
{
if( h_current>=h_count-1 ) return;
h_current++;
int n=0,w=0;
for( Ttable_data *d=data;
d!=NULL && n<=h_current;
n++,w+=d->width+1,d=d->nextc );
w -= xl+1;
if( w<0 ) return;
if( h_beg_print<w ) h_beg_print += w-h_beg_print;
}
void Ttable_iterator::up( void )
{
cursor_up_left( v_current, v_beg_print, yl, 2 );
}
void Ttable_iterator::down( void )
{
cursor_down_right( v_current, v_beg_print, yl, v_count, 2 );
}
void Ttable_iterator::top( void )
{
cursor_top_home( v_current, v_beg_print );
}
void Ttable_iterator::bottom( void )
{
cursor_bottom_end( v_current, v_beg_print, yl, v_count );
}
void Ttable_iterator::at( uint i )
{
cursor_at( i, v_current, v_beg_print, yl, v_count );
}
void Ttable_iterator::update_commands( void )
{
}
void Ttable_iterator::pgup( void )
{
for( uint i = 1; i < yl; i++ ) up();
}
void Ttable_iterator::pgdn( void )
{
for( uint i = 1; i < yl; i++ ) down();
}
//Ttable_iterator protected:
void Ttable_iterator::draw( void )
{
uint row, col;
char buf[256];
Ttable_data *c;
char ta;
int l, i, j, rx, ry, rxl, ryl;
get_clip_rect( rx, ry, rxl, ryl );
int end=min(yl,ry+ryl);
rxl+=rx;
for( i=max(0,ry),row=v_beg_print+i; i<end; i++,row++ )
{
c = data;
col = 0;
j = -h_beg_print-1;
while( c != NULL )
{
if( j>rxl ) break;
if( c->where == whTABLE )
{
goto_xy( j, i ); j += c->width + 1;
if( j>=rx )
{
txtf( "%c", frame_standard[3] );
ta = text_attr;
*buf = 0;
if( row < v_count )
fetch( buf, row, col, c->width );
buf[c->width] = 0;
if( ( l = c->width - strlen( buf ) ) < 0 ) l = 0;
if( c->align == atRIGHT ) txtf( "|r%c ", l );
direct_txt( buf );
if( c->align == atLEFT ) txtf( "|r%c ", l );
text_attr = ta;
}
}
c = c->nextc; col++;
}
goto_xy( j, i ); txtf( "%c", frame_standard[3] );
}
}
void Ttable_iterator::get_focused( void )
{
Titem::get_focused();
update_commands();
}
void Ttable_iterator::event_handler( Tevent &ev )
{
uint vc=v_current, hc=h_current;
Titem::event_handler( ev );
if( state( isFOCUSED ) )
switch( ev.code )
{
case evKEY_PRESS:
switch( ev.ASCII )
{
case kUP: case kSHIFT_UP:
up(); break;
case kDOWN: case kSHIFT_DOWN:
down(); break;
case kPG_UP: case kSHIFT_PG_UP:
pgup(); break;
case kPG_DN: case kSHIFT_PG_DN:
pgdn(); break;
case kHOME: case kSHIFT_HOME:
top(); break;
case kEND: case kSHIFT_END:
bottom(); break;
default:
if( flags(tfWHOLE_LINES) )
goto not_handled;
else
switch( ev.ASCII )
{
case kLEFT: case kSHIFT_LEFT:
left(); break;
case kRIGHT: case kSHIFT_RIGHT:
right(); break;
default:
goto not_handled;
}
}
if( (hc!=h_current || vc!=v_current) && !(get_shifts()&smSHIFT) )
hsel_org=h_current, vsel_org=v_current;
handled( ev ); redraw();
item_acted = this;
not_handled:
break;
#ifndef NOMOUSE
case evMOUSE_DOWN:
if( ev.INSIDE )
{
uint i, j=(uint) -1;
uint ih, jh=(uint) -1;
do
{
boolean vinside = (ev.LOCAL_Y>=0 && ev.LOCAL_Y<yl);
if( vinside || ev.code==evMOUSE_REP )
{
if( ev.LOCAL_Y >= 0 ) i = ev.LOCAL_Y; else i = 0;
i = v_beg_print + i;
if( !vinside )
{
if( i > v_current ) down(); else up();
i = v_current;
}
if( i >= v_count ) i = v_count - 1;
if( j != i )
{
v_current = i;
if( ev.code==evMOUSE_DOWN ) vsel_org = v_current;
redraw();
}
j = v_current;
}
if( !flags(tfWHOLE_LINES) )
{
boolean hinside = (ev.LOCAL_X>=0 && ev.LOCAL_X<xl);
if( hinside || ev.code==evMOUSE_REP )
{
if( ev.LOCAL_X >= 0 ) ih = ev.LOCAL_X; else ih = 0;
ih = h_beg_print + ih;
int xx=0, n=0;
for( Ttable_data *d=data; d!=NULL; xx+=d->width+1,d=d->nextc,n++ )
if( xx+d->width>ih ) break;
ih = n;
if( !hinside )
{
if( ih > h_current ) right(); else left();
ih = h_current;
}
if( ih >= h_count ) ih = h_count - 1;
if( jh != ih )
{